package com.qfly.main.authentication.handler;

import com.qfly.main.common.enums.ErrorCodeEnum;
import com.qfly.main.common.utils.ResultUtil;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Wisdytech.cn
 * com.qfly.main.authentication.handler.qflyAccessDeniedHandler
 *
 * @author hailin.zhl
 * @date 2018/12/04
 */
@Component
public class QflyAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        System.out.println(response.getStatus());
        ResultUtil.sendFail(request,response, ErrorCodeEnum.UNAUTHORIZED);
    }
}
